<template>
    <div style="height:100%;width:100%;position:relative;" ref="maindev">
        <div class="pagetop" :style="pagetopstyle">
            <div style="width:100%;">
                <el-col>
                    <div ref="buttondiv">
                        <table>
                            <tr>
                                <td>报告单元</td>
                                <td colspan='3'>
                                    <el-select v-model="searchobj.rptunitid" @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable clearable style="width:100%">
                                        <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                                    </el-select>
                                </td>
                                <td style="width:80px">报告项目</td>
                                <td>
                                    <rm-ddl-rptitem prgno="LIS413" isAllRpt="1" v-model="searchobj.rpt_itemcode" width="160px" :rptunitid="searchobj.rptunitid" :appendtobody="true" @change="rptitemChange">
                                    </rm-ddl-rptitem>
                                </td>
                                <td style="width:80px">标本号</td>
                                <td>
                                    <el-input size="small" style="width:160px;" placeholder="输入如1,2,5-8等格式" v-model="searchobj.sampleno"></el-input>
                                </td>
                                <td style="width:80px">检验医生</td>
                                <td>
                                    <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchobj.report_user" width="160px" @change="reportuserChange"></rm-ddl-common>
                                </td>
                                <td>送检医生</td>
                                <td>
                                    <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchobj.req_docno" width="160px" @change="reqdocChange"></rm-ddl-common>
                                </td>
                            </tr>
                            <tr>
                                <!-- <td>标本日期</td> -->
                                <td>
                                    <el-dropdown @command="handleCommand" style="font-size: 12px;">
                                        <u class="el-dropdown-link">
                                            {{ datename }}
                                        </u>
                                        <el-dropdown-menu slot="dropdown">
                                            <el-dropdown-item command="标本日期">
                                                <font font-size="12px">标本日期</font>
                                            </el-dropdown-item>
                                            <el-dropdown-item command="审核日期">
                                                <font font-size="12px">审核日期</font>
                                            </el-dropdown-item>
                                            <el-dropdown-item command="报告日期">
                                                <font font-size="12px">报告日期</font>
                                            </el-dropdown-item>
                                        </el-dropdown-menu>
                                    </el-dropdown>
                                </td>
                                <td v-if="daytype =='1' ">
                                    <el-date-picker v-model="searchobj.sample_startdt" :able="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:150px;" :clearable="false">
                                    </el-date-picker>
                                </td>
                                <td v-else-if="daytype=='2'">
                                    <el-date-picker v-model="searchobj.rechk_startdt" type="datetime" placeholder="选择日期" style="width:150px">
                                    </el-date-picker>
                                </td>
                                <td v-else>
                                    <el-date-picker v-model="searchobj.report_startdt" type="datetime" placeholder="选择日期" style="width:150px">
                                    </el-date-picker>
                                </td>
                                <td align="center" style="width:20px;padding:0 0 0 0px">至</td>
                                <td v-if="daytype =='1' ">
                                    <el-date-picker v-model="searchobj.sample_enddt" type="date" :able="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:150px" :clearable="false">
                                    </el-date-picker>
                                </td>
                                <td v-else-if="daytype=='2'">
                                    <el-date-picker v-model="searchobj.rechk_enddt" type="datetime" placeholder="选择日期" style="width:150px">
                                    </el-date-picker>
                                </td>
                                <td v-else>
                                    <el-date-picker v-model="searchobj.report_enddt" type="datetime" placeholder="选择日期" style="width:150px">
                                    </el-date-picker>
                                </td>
                                <td>数值结果</td>
                                <td>
                                    &lt; <el-input size="small" style="width:45px" v-model="searchobj.result_min" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                                    数值结果&gt;<el-input size="small" style="width:47px" v-model="searchobj.result_max" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                                </td>
                                <td>标本类型</td>
                                <td>
                                    <el-select v-model="searchobj.specimen_code" @dblclick.native="popMultipleChk(searchobj.specimen_code, 'specimen_code', specimenOption, '请选择标本类型')" filterable clearable style="width:100%">
                                        <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data" :label="item.display"></el-option>
                                    </el-select>
                                    <!-- <rm-ddl-common ref="ddlspecimen" datatype="specimen" dataname="标本类型" v-model="searchobj.specimen_code" width="160px"></rm-ddl-common> -->
                                </td>
                                <td>报告备注</td>
                                <td>
                                    <rm-ddl-common datatype="seccode" kindno="REPORTCOMM" dataname="备注" v-model="searchobj.report_comm" width="160px" @change="reportcommChange"></rm-ddl-common>
                                </td>
                                <td style="width:80px">送检医院</td>
                                <td>
                                    <!-- 
                                    <el-select v-model="searchobj.hospcode" @dblclick.native="popMultipleChk(searchobj.hospcode,'hospcode',hospOption,'请选择送检医院')" filterable style="width:160px" clearable>
                                        <el-option v-for="(item,index) in hospOption" :key="index" :value="item.value" :label="item.label"></el-option>
                                    </el-select>-->
                                    <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchobj.hospcode" width="160px" @change="hospChange"></rm-ddl-common> 
                                </td>
                            </tr>
                            <tr>
                                <td>多项目条件</td>
                                <td colspan="3">
                                    <el-select v-model="searchobj.resultcomb" clearable style="width:170px">
                                        <el-option v-for="(item,index) in resultcombOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                    </el-select>
                                    <el-button align="right" @click="OpenResultComb">自定义</el-button>
                                </td>
                                <td>文字结果</td>
                                <td>
                                    <el-input size="small" style="width:110px;" v-model="searchobj.result_str"></el-input>
                                    <el-checkbox v-model="searchobj.result_mh" true-label="1" false-label="0">模糊</el-checkbox>
                                </td>
                                <td>临床诊断</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.pat_diag"></el-input>
                                </td>

                                <td colspan="4" style="align:right">
                                    <el-link :underline="false" @click="btn_openselEvent">{{show_sel?"收起▲":"展开▼"}}</el-link>
                                    <el-button icon="el-icon-search" v-has="'PINQUERY'" type="primary" @click="btnQuery">查询</el-button>
                                    <el-button icon="el-icon-delete" @click="btn_Clear">清除</el-button>
                                    <el-button icon="el-icon-printer" @click="printrecord()" v-has="'PPRINT'">打印</el-button>
                                    <el-button icon="el-icon-edit-outline" @click="RptStyleSetting()" v-has="'PPRINT'">设计</el-button>
                                    <el-button icon="el-icon-upload2" v-has="'PEXPORT'" @click="btnPreExportRpt()">导出</el-button>
                                    <el-button @click="setExportColumn">导出列设置</el-button>
                                </td>
                            </tr>
                            <tr v-show="show_sel">
                                <td>病人类型</td>
                                <td>
                                    <el-select v-model="searchobj.pat_typecode" @dblclick.native="popMultipleChk(searchobj.pat_typecode,'pat_typecode',pattypeOption,'病人类型选择')" filterable clearable style="width:100%">
                                        <el-option v-for="(item,index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                    </el-select>
                                </td>
                                <td>加急</td>
                                <td>
                                    <el-select v-model="searchobj.emer_flag" filterable clearable style="width:100%">
                                        <el-option value="0" label="非急" key="0"></el-option>
                                        <el-option value="1" label="急" key="1"></el-option>
                                    </el-select>
                                </td>
                                <td>审核状态</td>
                                <td>
                                    <el-select v-model="searchobj.ischeck" placeholder="请选择" style="width:160px">
                                        <el-option key="all" label="全部" value="all"></el-option>
                                        <el-option key="0" label="未审核" value="0"></el-option>
                                        <el-option key="1" label="已审核" value="1"></el-option>
                                    </el-select>
                                </td>
                                <td>文字描述</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.txtinfo1"></el-input>
                                </td>
                                <td>检验意见</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.lab_advice"></el-input>
                                </td>
                                <td>病区组</td>
                                <td>
                                    <rm-ddl-common :appendtobody="true" datatype="wardcomb" kindno="WD" dataname="病区" v-model="searchobj.combno" width="160px" @change="combChange"></rm-ddl-common>
                                </td>
                            </tr>
                            <tr v-show="show_sel">
                                <td>申请科室</td>
                                <td colspan='3'>
                                    <el-select v-model="searchobj.req_deptno" @dblclick.native="popMultipleChk(searchobj.req_deptno, 'req_deptno', deptOption, '科室选择')" filterable clearable style="width:100%">
                                        <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                                    </el-select>
                                </td>
                                <td>姓名剔除文字</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.nameoutstr"></el-input>
                                </td>
                                <td>病历号</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.pat_no"></el-input>
                                </td>
                                <td>年龄</td>
                                <td>
                                    <el-input size="small" style="width:69px;" v-model="searchobj.agemin" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>&nbsp;至&nbsp;
                                    <el-input size="small" style="width:69px;" v-model="searchobj.agemax" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                                </td>
                                <td></td>
                                <td colspan="2">
                                    <el-checkbox v-model="searchobj.resultnumflag" true-label="1" false-label="0">原始数值</el-checkbox>
                                    <el-checkbox v-model="searchobj.nameflag" true-label="1" false-label="0">剔除无姓名</el-checkbox>
                                    <el-checkbox v-model="searchobj.barcodeflag" true-label="1" false-label="0">剔除无条码</el-checkbox>
                                </td>
                            </tr>
                            <tr v-show="show_sel">
                                <td>所属病区</td>
                                <td colspan="1">
                                    <el-select v-model="searchobj.req_wardno" @dblclick.native="popMultipleChk(searchobj.req_wardno, 'req_wardno', wardOption, '病区选择')" filterable clearable style="width:100%">
                                        <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                                    </el-select>
                                </td>
                                <td>性别
                                </td>
                                <td>
                                    <el-select v-model="searchobj.pat_sex" placeholder="请选择" style="width:160px">
                                        <el-option key="0" label="全部" value="0"></el-option>
                                        <el-option key="1" label="男" value="1"></el-option>
                                        <el-option key="2" label="女" value="2"></el-option>
                                    </el-select>
                                </td>
                                <td>身份证号</td>
                                <td>
                                    <el-input size="small" style="width:160px" v-model="searchobj.pat_idcardno" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                                </td>
                                <td>病人ID</td>
                                <td>
                                    <el-input size="small" style="width:160px;" v-model="searchobj.pat_id"></el-input>
                                </td>
                                <td>混样报告</td>
                                <td>
                                    <el-select v-model="searchobj.mixrpt" placeholder="请选择" style="width:100%">
                                        <el-option key="0" label="全部报告" value="0"></el-option>
                                        <el-option key="1" label="混样主报告和非混样报告" value="1"></el-option>
                                        <el-option key="2" label="混样明细报告和非混样报告" value="2"></el-option>
                                        <el-option key="3" label="非混样报告" value="3"></el-option>
                                        <el-option key="4" label="混样报告" value="4"></el-option>
                                        <el-option key="5" label="仅混样主报告" value="5"></el-option>
                                        <el-option key="6" label="仅混样明细报告" value="6"></el-option>
                                    </el-select>
                                </td>
                                <td colspan="3">
                                    <el-checkbox v-model="searchobj.upresult_flag" true-label="1" false-label="0">上次结果</el-checkbox>
                                    <el-checkbox v-model="searchobj.firstresult_flag" true-label="1" false-label="0">首次结果</el-checkbox>

                                    <el-checkbox v-model="searchobj.dblclickdel" true-label="1" false-label="0">双击明细剔除</el-checkbox>
                                </td>
                            </tr>
                        </table>
                        <!-- </template>
                        </vxe-toolbar> -->
                    </div>
                </el-col>
            </div>
        </div>
        <div :style="pagecenter">
            <div :style="middle_center">
                <vxe-table :data.sync="report_date" :loading="report_Loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border :height="tableheight" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="reporttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" header-align="center" @cell-dblclick="DbLdel" @header-cell-click="handleHeaderClick">
                    <vxe-table-column type="index" align="center" title="序号" width="40"></vxe-table-column>
                    <vxe-table-column field="pat_no" sortable title="病人号" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_id" sortable title="病人ID" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_name" align="center" sortable title="姓名" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_sexname" align="center" sortable title="性别" width="35" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_nationna" align="center" sortable title="民族" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_agestr" sortable title="年龄" width="40" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_birth" sortable title="生日" width="140" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_dept" sortable title="申请科室" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_ward" sortable title="病区" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_bedno" align="center" sortable title="床号" width="50" show-overflow></vxe-table-column>
                    <vxe-table-column field="sampledate" align="center" sortable title="样本日期" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="sampleno" align="center" sortable title="标本号" width="80" show-overflow :sort-width="20"></vxe-table-column>
                    <vxe-table-column field="barcode" align="center" sortable title="条码号" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="itemcode_en" sortable title="英文缩写" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="rpt_itemname" sortable title="项目名称" width="220" show-overflow></vxe-table-column>
                    <vxe-table-column field="result_str" sortable title="检验结果" width="80" show-overflow :sort-width="40"></vxe-table-column>
                    <vxe-table-column field="orig_result_num" sortable title="原始数值结果" width="80" show-overflow :sort-width="40" v-if="searchobj.resultnumflag=='1'"></vxe-table-column>
                    <vxe-table-column field="redo_result" sortable title="复查前结果" width="80" show-overflow :sort-width="40"></vxe-table-column>
                    <vxe-table-column field="emer_flag" align="center" sortable title="加急" width="40" show-overflow></vxe-table-column>
                    <vxe-table-column field="specimen" align="center" sortable title="标本类型" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_docname" align="center" sortable title="送检医生" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="report_user" align="center" sortable title="检验医生" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="rechk_user" align="center" sortable title="审核医生" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_diag" sortable title="临床诊断" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="report_comm" sortable title="报告备注" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="lab_advice" sortable title="检验意见" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="txtinfo1" sortable title="文字描述1" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="txtinfo2" sortable title="文字描述2" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="hospna" sortable title="送检医院" width="130" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_AgeYear" sortable title="年龄岁数" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_idcardno" sortable title="身份证/护照号" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_phone" align="center" sortable title="联系电话" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_address" sortable title="家庭住址" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="rptunitname" align="center" sortable title="报告单元" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="result1" sortable title="结果1" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="result2" sortable title="结果2" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="result3" sortable title="结果3" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="result4" sortable title="结果4" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="result5" sortable title="结果5" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="result6" sortable title="结果6" width="80" show-overflow></vxe-table-column>
                    <vxe-table-column field="sampled_dt" align="center" sortable title="采样时间" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="input_dt" align="center" sortable title="核收时间" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="report_dt" align="center" sortable title="报告时间" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="rechk_dt" align="center" sortable title="审核时间" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="specimen_comm" align="center" sortable title="标本状态" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="Reserve1" sortable align="center" title="备用1" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="instrna" sortable title="仪器" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column field="cp_lastresult" sortable title="上次结果" width="100" show-overflow v-show="searchobj.upresult_flag=='1'"></vxe-table-column>
                    <vxe-table-column field="cp_lastresult_dt" sortable title="上次结果时间" width="120" show-overflow v-show="searchobj.upresult_flag=='1'"></vxe-table-column>
                    <vxe-table-column field="cp_firstresult" sortable title="首次结果" width="100" show-overflow v-show="searchobj.firstresult_flag=='1'"></vxe-table-column>
                    <vxe-table-column field="cp_firstresult_dt" align="center" sortable title="首次结果时间" width="120" show-overflow v-show="searchobj.firstresult_flag=='1'"></vxe-table-column>
                    <template v-slot:fix>
                        <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">{{cntmsg}}</span>
                            <div style="clear:both"></div>
                        </div>
                    </template>
                </vxe-table>
            </div>
        </div>
        <!--多选弹窗--->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
        </el-dialog>
        <!-- :style="{ height: bSaveResultComb?'500px':'400px' }"   -->
        <el-dialog width="850px" height="600px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="结果组合查询条件" :visible.sync="bResultComb" :destroy-on-close="true">
            <div style="height:90px" v-show="bSaveResultComb">
                <table style="width: 100%; font-size: 12px;">
                    <col style="width: 10%;" />
                    <col style="width: 23%;" />
                    <col style="width: 10%;" />
                    <col style="width: 23%;" />
                    <col style="width: 10%;" />
                    <col style="width: 23%;" />
                    <tr>
                        <td>
                            条件代码
                        </td>
                        <td>
                            <el-input v-model="saveobj.queryresultno" style="width:100%" ref="input1" @keyup.enter.native="NextFocus(1)"></el-input>
                        </td>
                        <td>
                            条件名称
                        </td>
                        <td>
                            <el-input v-model="saveobj.queryresultname" style="width:100%" ref="input2" @keyup.enter.native="NextFocus(2)"></el-input>
                        </td>
                        <td>
                            用户
                        </td>
                        <td>
                            <rm-ddl-common datatype="userinfo" dataname="用户" v-model="saveobj.createuser" width="100%" :disabled="utype!='G'"></rm-ddl-common>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            备注
                        </td>
                        <td colspan="5">
                            <el-input type="textarea" v-model="saveobj.description" rows="2" ref="input3" @keyup.enter.native="NextFocus(3)"></el-input>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="text-align:right;height:30px">
                <el-button icon="el-icon-save" style="align:right" @click="btnSure" v-show="!bSaveResultComb" type="primary">确定</el-button>
                <el-button icon="el-icon-save" style="align:right" @click="btnCancel" v-show="!bSaveResultComb">取消</el-button>
                <el-button icon="el-icon-plus" style="align:left" @click="addItem(1)">新增明细</el-button>
                <el-button icon="el-icon-delete" style="align:left" @click="delItem(1)">删除明细</el-button>
                <el-button icon="el-icon-save" style="align:right" @click="btnToSave()" v-show="!bSaveResultComb&&addPower">另存为</el-button>
                <el-button icon="el-icon-save" style="align:right" @click="btnSave()" v-show="bSaveResultComb" type="primary">保存</el-button>
                <el-button icon="el-icon-save" style="align:right" @click="btnGoBack()" v-show="bSaveResultComb">返回</el-button>
            </div>
            <div style="height:270px">
                <vxe-table show-overflow ref="nomatch_table" :data.sync="ComList" height="auto" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" @cell-dblclick="CellDblclick" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe header-align="center">
                    <vxe-table-column field="seq" title="序号" align="center" width="55" :edit-render="{name: 'input'}" sortable></vxe-table-column>
                    <vxe-table-column field="rpt_itemname" title="报告项目(双击弹窗)" width="145" :edit-render="{name:'input', autoselect: true, attrs: {readonly: true}}" sortable></vxe-table-column>
                    <vxe-table-column field="resistrules" title="耐药机制" width="150" :edit-render="{type: 'default'}">
                        <template v-slot="{ row }">
                            <el-select v-model="row.resistrules" @dblclick.native="popMultipleChk_R(row.resistrules, 'resistrules', rescodeOption, '耐药机制选择')" style="width: 100%;" filterable clearable>
                                <el-option v-for="(item, index) in rescodeOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                            </el-select>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="lowlimit" title="数值结果<" width="90" :edit-render="{name: 'input',autoselect: true}" sortable></vxe-table-column>
                    <vxe-table-column field="uplimit" title="数值结果>" width="90" :edit-render="{name: 'input',autoselect: true,}" sortable></vxe-table-column>
                    <vxe-table-column field="txtoperator" title="文字结果条件" width="95" sortable>
                        <template v-slot="{ row }">
                            <el-select v-model="row.txtoperator" placeholder="请选择">
                                <el-option v-for="item in txtoperatorOptions" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="txtresults" title="文字结果（多个,隔开）" width="160" :edit-render="{name: 'input',autoselect: true}" sortable></vxe-table-column>
                    <vxe-table-column field="txtlike" sortable title="文字模糊匹配" width="100" align="center">
                        <template v-slot="{ row }">
                            <el-checkbox v-model="row.txtlike" true-label="1" false-label="0"></el-checkbox>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="mustinclude" title="必选条件" width="60" align="center">
                        <template v-slot="{ row }">
                            <el-checkbox v-model="row.mustinclude" true-label="1" false-label="0"></el-checkbox>
                        </template>
                    </vxe-table-column>
                </vxe-table>
            </div>
            <!-- <div class="detail-operation"> -->
            <!-- <div style="font-size:17px;padding:3px;background-color:#fff;text-align:center;font-weight:bold">
                <el-button icon="el-icon-plus" style="align:left" class="el-button--310" @click="addItem()">新增明细</el-button>
                <el-button icon="el-icon-delete" style="align:left" class="el-button--310" @click="delItem()">删除明细</el-button>
            </div> -->
        </el-dialog>
        <el-dialog width="1000px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="选择报告项目" :visible.sync="rpt_itemdialog" :destroy-on-close="true">
            <rm-pop-rptitem prgno="LIS156" @cancel="rpt_itemdialog=false;" :isAllRpt="1" @selitem="rpt_itemchange" :rptunitid="txtrptunit"></rm-pop-rptitem>
        </el-dialog>
        <el-dialog width="1000px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="耐药机制选择" :visible.sync="dialogMultipleVisible_R" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog_R"></rm-SqlMultiple>
        </el-dialog>
        <!--导出列选择-->
        <el-dialog title="导出列模板选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false" v-if="chooseColumndialogVisible">
            <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset"></rm-excolsetting>
        </el-dialog>
        <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
    </div>
</template>


<script>
import { Promise } from "q";
import { invalid } from "moment";
import XEUtils from "xe-utils"; //引入工具类
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
export default {
    name: "LIS413",
    components: { RmExcolsetting },
    data() {
        return {
            pagetopstyle: {
                height: "105px",
            },
            pagecenter: {
                position: "absolute",
                top: "108px",
                bottom: "0px",
                overflow: "auto",
                width: "100%",
                left: "0px",
            },
            middle_center: {
                position: "absolute",
                height: "100%",
                right: "0px",
                left: "0px",
                overflow: "auto",
            },
            show_sel: false,
            searchobj: {
                //查询框初始值
                rptunitid: "", //报告单元ID *1
                rpt_itemcode: "", //报告项目
                report_user: "", //检验医生 *\
                pat_diag: "", //临床诊断
                hospcode: "", //送检医院 *1
                sample_startdt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                sample_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                rechk_startdt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 00:00:00"),
                rechk_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 23:59:59"),
                report_startdt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 00:00:00"),
                report_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 23:59:59"),
                result_min: "", //数值min
                result_max: "", //数值max
                specimen_code: "", //标本类型 *
                report_comm: "", //报告备注 **
                pat_idcardno: "", //身份证号
                sampleno: "", //标本号
                result_str: "", //文字结果
                result_mh: "0", //模糊查询
                req_docno: "", //送检医生 *\
                pat_typecode: "", //病人类型 *
                ischeck: "", //审核状态
                txtinfo1: "", //文字描述
                lab_advice: "", //检验意见
                combno: "", //病区组 *
                req_deptno: "", //科室 *
                nameoutstr: "", //剔除姓名
                pat_no: "", //病历号
                pat_id: "",//病人唯一号
                agemin: "", //年龄min
                agemax: "", //年龄max
                nameflag: "", //剔除无姓名
                barcodeflag: "", //剔除无条码
                upresult_flag: "0",
                firstresult_flag: "0",
                pat_sex: "0", //性别
                req_wardno: "", //病区 *
                mixrpt: "0",
                resultcomb: "", //多项目条件
                dblclickdel: "0", //双击剔除明细
                resultnumflag: "0",//显示原始数值结果列
                emer_flag:"",
            },
            selnum: 0,
            saveobj: {
                queryresultno: "",
                queryresultname: "",
                createuser: "",
                description: "",
            },
            txtoperatorOptions: [
                {
                    value: "In",
                    label: "等于",
                },
                {
                    value: "NotIn",
                    label: "不等于",
                },
            ],
            report_Loading: false,
            dialogMultipleVisible: false,
            bMultipleItem: false,
            bResultComb: false,
            bSaveResultComb: false,
            rpt_itemdialog: false,
            addPower: false, // 组合查询条件授权
            ComList: [],
            tempCombList: [],
            report_date: [],
            tableColumn: [],
            option1: [],
            option2: [],
            rptunitOption: [],
            hospOption: [],
            specimenOption: [],
            pattypeOption: [],
            deptOption: [],
            wardOption: [],
            userOption: [],
            doctorOption: [],
            resultcombOption: [],
            selrow: {},
            tableheight: "auto",
            buttonWidth: "",
            rpt_aomount: 0,
            styleid: 0,
            txtrptunit: "",
            operate: "",
            multichktitle: "",
            fieldname: "",
            utype: "",
            daytype: "1",
            datename: "标本日期",
            sqlstr: "",
            //耐药机制
            rescodeOption: [],
            dialogMultipleVisible_R: false,
            //导出
            excolPro: "lis413",
            allTableCol: [],
            chooseColumndialogVisible: false,
            //多项目导出
            cntmsg:"合计:0",
            rptitemname: "",
            reportusername: "",
            reqdocname: "",
            reportcommname: "",
            hospname: "",
            combname: "",
            exportsort: "",
        };
    },
    created() {
        this.loginUser();
        this.getSavePower();
        this.btn_Clear();
    },
    // watch: {
    //     rptunitid(val) {
    //         this.sel_rptunit = val
    //     },
    // },
    mounted() {
        this.initOption();
        this.GetOption();
        this.$refs.excolset.colSettingToDB();
    },
    updated() {
        this.getButtonWidth();
    },
    methods: {
        loginUser() {
            this.utype = this.$tool.getSession(this.$tool.loginutype);
            if (this.utype == "G") {
                this.saveobj.createuser = "_Global_";
            } else {
                this.saveobj.createuser = this.$tool.getSession(this.$tool.loginusername);
            }
        },
        OpenResultComb() {
            //无需初始化表格内的数值，方便重复查询
            //自定义与选择查询重叠||二选一，待测试
            //先满足表格直接查询,再考虑满足保存，可以优先画好全部界面。
            this.ComList = XEUtils.clone(this.tempCombList, true);
            this.bResultComb = true;
        },
        CellDblclick({ row, column }) {
            // 报告项目弹窗
            if (column.property == "rpt_itemname") {
                this.selrow = row;
                this.rpt_itemdialog = true;
            }
        },
        btnSure() {
            console.log("this.ComList", this.ComList);
            this.searchobj.resultcomb = "";
            this.tempCombList = XEUtils.clone(this.$refs.nomatch_table.getTableData().fullData, true);
            this.bResultComb = false;
        },
        btnCancel() {
            // this.ComList=this.tempCombList
            this.ComList = XEUtils.clone(this.tempCombList, true);
            this.bResultComb = false;
        },
        rpt_itemchange(code, name) {
            this.selrow.rpt_itemcode = code;
            this.selrow.rpt_itemname = name;
            this.getResultArea(2, code);
            this.rpt_itemdialog = false;
        },
        async getResultArea(flag, rpt_itemcode) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    data: {
                        action: "get_resultarea",
                        rpt_itemcode: rpt_itemcode,
                    },
                });
                console.log(res);
                if (flag == "1") {
                    this.searchobj.result_min = res[0].ref_l;
                    this.searchobj.result_max = res[0].ref_h;
                } else if (flag == "2") {
                    this.selrow.lowlimit = res[0].ref_l;
                    this.selrow.uplimit = res[0].ref_h;
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },
        addItem() {
            this.$refs.nomatch_table
                .insert({
                    queryresultno: this.saveobj.queryresultno,
                    seq: this.$refs.nomatch_table.tableFullData.length > 0 ? (Math.floor(this.$refs.nomatch_table.tableFullData[this.$refs.nomatch_table.tableFullData.length - 1].seq / 10) + 1) * 10 : 10,
                    txtoperator: "In",
                    txtlike: 0,
                    mustinclude: "1",
                    resistrules: "",
                })
                .then(({ row }) => {
                    this.$nextTick(() => {
                        this.$refs.nomatch_table.setCurrentRow(row);
                    });
                });
        },
        DbLdel() {
            try {
                var delrow = this.$refs.reporttable.getCurrentRow();
                if (delrow && this.searchobj.dblclickdel == "1") {
                    var alld = this.$refs.reporttable.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.reporttable.remove(delrow);
                    let havedata = this.$refs.reporttable.tableData;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        // let selectrow = havedata[rowindex];
                        // this.$refs.reporttable.setCurrentRow(selectrow);
                    } else {
                        this.$message({
                            message: "请先选中要删除的明细！",
                            type: "warning",
                        });
                        this.$refs.reporttable.setCurrentRow(null);
                    }
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        handleHeaderClick(event) {
            if(event.triggerSort){
                this.exportsort = "";
                return;
            } 
            // 处理header点击事件逻辑，例如排序、筛选等
            if(this.exportsort && this.exportsort.indexOf(event.column.property + " desc") > -1) {
                //包含倒序的转成正序
                this.exportsort = event.column.property + " asc";
            } else {
                //没有的直接加倒序的
                this.exportsort = event.column.property + " desc";
            }
        },
        delItem() {
            try {
                var delrow = this.$refs.nomatch_table.getCurrentRow();
                if (delrow) {
                    var alld = this.$refs.nomatch_table.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.nomatch_table.remove(delrow);
                    let havedata = this.$refs.nomatch_table.tableData;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.nomatch_table.setCurrentRow(selectrow);
                    } else {
                        this.$message({
                            message: "请先选中要删除的明细！",
                            type: "warning",
                        });
                        this.$refs.nomatch_table.setCurrentRow(null);
                    }
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        btnToSave() {
            this.bSaveResultComb = true;
            setTimeout(() => {
                this.$refs.input1.focus();
            }, 30);
        },
        //组合查询条件授权
        async getSavePower() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "get_savepower",
                    },
                });
                this.addPower = res;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        async btnSave() {
            try {
                let data = this.$refs.nomatch_table.getTableData().fullData;
                for (let i = 0, len = data.length; i < len; i++) {
                    let tempseq = (i + 1) * 10;
                    if (tempseq !== data[i].seq) {
                        data[i].seq = tempseq;
                    }
                    data[i].queryresultno = this.saveobj.queryresultno; //修正主键
                }
                const res = await this.$tool.request({
                    url: "LIS/LIS1/LIS156",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "addsearchadition",
                        utype: 1,
                        addparam: this.saveobj,
                        upt: data,
                    },
                });
                if (res.errcode == "1") {
                    this.$message.success("保存成功！");
                    this.Freshcomb(); //保存成功刷新主键
                    this.bSaveResultComb = false;
                    this.bResultComb = false;
                } else {
                    this.$message.erro(res.errmsg);
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },
        btnGoBack() {
            this.bSaveResultComb = false;
        },
        async initOption() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    data: {
                        action: "getOption",
                    },
                });
                this.rptunitOption = res.rptunitOption;
                this.specimenOption = res.specimenOption;
                this.pattypeOption = res.pattypeOption;
                this.deptOption = res.deptOption;
                this.wardOption = res.wardOption;
                this.userOption = res.userOption;
                this.doctorOption = res.doctorOption;
                this.resultcombOption = res.resultcombOption;
                if(res.secHospCodeOption && res.secHospCodeOption != ""){
                    this.searchobj.hospcode = res.secHospCodeOption;
                }
                //this.hospOption = res.hospOption;
                this.rescodeOption = res.rescodeOption;
                //送检医院添加所有医院列，用于查询所有数据，当前医院数据，所有医院数据
               /* var allHosp = {
                    value: "All",
                    label: "所有医院",
                    inputcode: "SYYY",
                };
                this.hospOption = res.hospOption;
                this.hospOption.unshift(allHosp);
                */
            } catch (e) {
                this.$message.warning(e);
            }
        },
        async Freshcomb() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    data: {
                        action: "getOption",
                    },
                });
                this.resultcombOption = res.resultcombOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        popMultipleItem() {
            this.bMultipleItem = true;
        },
        popMultipleChk(e, fieldname, option, title) {
            console.log("233");
            let temp = XEUtils.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.multichktitle = title;
            this.dialogMultipleVisible = true;
        },
        closedialog(value, name) {
            if (value != "close") {
                this.searchobj[name] = value;
            }
            this.dialogMultipleVisible = false;
        },
        GetOption() {
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    data: {
                        action: "get_styleid",
                    },
                })
                .then((res) => {
                    console.log("res", res);
                    this.styleid = res.styleid;
                })
                .catch((e) => {
                    console.log("error", e);
                });
        },
        btnQuery() {
            this.report_Loading = true;
            this.sqlWhere = "";
            this.sqlstr = "";
            this.report_date = [];
            this.cntmsg = "合计:0";
            if (this.tempCombList.length > 0) {
            }
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS413",
                    method: "post",
                    data: {
                        action: "lab_report_query",
                        ...this.searchobj,
                        comblist: this.tempCombList,
                        daytype: this.daytype, //标本日期(1) 审核日期(2)报告日期(3)
                    },
                })
                .then((res) => {
                    this.report_date = res.RData.Data;
                    this.sqlWhere = res.sqlwhere;
                    this.report_Loading = false;
                    this.rpt_aomount = res.RData.total;
                    this.cntmsg = "合计:"+     this.rpt_aomount;
                    if(res.selcnt==5000&&res.RData.total<5000)
                    {
                        cntmsg = "使用多项目数据统计5000行，多项目过滤后展示"+this.rpt_aomount+"行，全部数据总数以导出为准。";
                    }
                    if (res.RData.total >= 5000) {
                        this.$message({
                            type: "info",
                            message: "超过5000行只显示前5000行数据！",
                        });
                    }
              
                    this.show_sel = true;
                    this.sqlstr = res.sql;
                    this.btn_openselEvent();
                })
                .catch((e) => {
                    this.$message.error(e);
                    this.report_Loading = false;
                });
        },

        btn_openselEvent() {
            let mainheight = this.$refs.maindev.offsetHeight;
            this.show_sel = !this.show_sel;
            this.$nextTick(() => {
                if (this.show_sel) {
                    this.pagetopstyle.height = "210px";
                    this.pagecenter.top = "213px";
                    this.tableheight = mainheight - 213;
                } else {
                    this.pagetopstyle.height = "105px";
                    this.pagecenter.top = "110px";
                    this.tableheight = mainheight - 110;
                }
            });
        },
        btn_Clear() {
            this.show_sel = false;
            this.report_Loading = false;
            this.report_date = [];
            this.sqlWhere = "";
            this.tempCombList = [];
            this.ComList = [];
             this.rpt_aomount = 0;
             this.cntmsg = "合计:"+     this.rpt_aomount;
            this.searchobj = {
                //查询框初始值
                rptunitid: "", //报告单元ID*
                rpt_itemcode: "", //报告项目
                report_user: "", //检验医生
                pat_diag: "", //临床诊断
                hospcode: "", //送检医院
                sample_startdt: XEUtils.toDateString(XEUtils.getWhatDay(new Date(), -7), XEUtils.toDateString(new Date(), "yyyy-MM-dd")),
                sample_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                rechk_startdt: XEUtils.toDateString(XEUtils.getWhatDay(new Date(), -7), XEUtils.toDateString(new Date(), "yyyy-MM-dd 00:00:00")),
                rechk_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 23:59:59"),
                report_startdt: XEUtils.toDateString(XEUtils.getWhatDay(new Date(), -7), XEUtils.toDateString(new Date(), "yyyy-MM-dd 00:00:00")),
                report_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd 23:59:59"),
                result_min: "", //数值min
                result_max: "", //数值max
                specimen_code: "", //标本类型*
                report_comm: "", //报告备注
                pat_idcardno: "", //身份证号
                sampleno: "", //标本号
                result_str: "", //文字结果
                result_mh: "0", //文字模糊
                req_docno: "", //送检医生
                pat_typecode: "", //病人类型*
                ischeck: "", //审核状态
                txtinfo1: "", //文字描述
                lab_advice: "", //检验意见
                combno: "", //病区组
                req_deptno: "", //科室
                nameoutstr: "", //剔除姓名
                pat_no: "", //病历号
                pat_id: "",//病人唯一号
                agemin: "", //年龄min
                agemax: "", //年龄max
                nameflag: "", //剔除无姓名
                barcodeflag: "", //剔除无条码
                upresult_flag: "0",
                firstresult_flag: "0",
                pat_sex: "0", //性别
                req_wardno: "", //病区
                mixrpt: "0",
                resultcomb: "", //多项目条件
                dblclickdel: "0",
            };
        },
        //阳性表打印及预览修改为JSON
        printrecord() {
            this.styleid = "5077";
            let printdata = this.$refs.reporttable.afterFullData;
            if (printdata.length == 0) {
                this.$message.error("错误：没有要打印的数据！");
            } else {
                let column = this.$refs.reporttable.getTableColumn().tableColumn;
                let str = JSON.stringify(this.$pub.InitColumn(column));
                str += "\r";
                str += JSON.stringify(printdata);
                let sql = btoa(encodeURIComponent(str));
                jsObj.PrintCustomJsonReport(this.styleid, sql, "admin", "阳性表", "");
            }
        },
        RptStyleSetting() {
            this.styleid = "5077";
            var user = this.$tool.getSession(this.$tool.loginuserno);
            if (user != "admin") {
                this.$message.error("如需调整样式请联系管理员。");
            } else {
                var data = this.$refs.reporttable.tableData;
                if (data.length > 0) {
                    const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                    let column = this.$refs.reporttable.getTableColumn().tableColumn;
                    let str = JSON.stringify(this.$pub.InitColumn(column));
                    str += "\r";
                    str += JSON.stringify(data);
                    let sql = btoa(encodeURIComponent(str));
                    jsObj.SetCustomJsonPrintConfig(this.styleid, sql, "admin", "阳性表");
                    rload.close();
                } else {
                    this.$message.error("错误：没有要打印的数据！");
                }
            }
        },
        reportRowName({ row, rowIndex }) {
            if (row.rechk_dt != "" && row.rechk_dt != " " && row.rechk_dt != null) {
                if (XEUtils.toNumber(row.print_count) > 0) {
                    return "rm-gray"; //审核过打印的
                } else {
                    return "colrow"; //没打印的
                }
            }
        },
        NextFocus(index) {
            if (index > 2) return false;
            var that = this;
            var focusIndex = index + 1;
            setTimeout(function () {
                that.$refs["input" + focusIndex].focus();
            }, 1);
        },
        reportCellName({ row, rowIndex, column, columnIndex }) {
            if (column.property == "alter_flag") {
                if (row.alter_flag != "0") {
                    return "rm_cell_red";
                }
            }
            if (column.property == "emer_flag") {
                if (row.emer_flag != "0") {
                    return "rm_cell_green";
                }
            }
            if (column.property == "redo_flag") {
                if (row.redo_flag != "0" && row.redo_flag != "1") {
                    return "rm_cell_yellow";
                }
            }
        },
        getButtonWidth() {
            this.buttonWidth = this.$refs.buttondiv.offsetWidth + "px";
        },
        setExportColumn() {
            let allColumnList = [];
            this.$refs.reporttable.getColumns().forEach((element) => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property,
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
        btnPreExportRpt() {
            if (this.rpt_aomount >= 5000) {
                 this.report_Loading = true;
                this.$message({
                    type: "info",
                    message: "全部数据超出页面最大可显示的5000条，正在获取全部数据并导出，请耐心等待。",
                });
                this.$tool
                    .request({
                        url: "LIS/LIS4/LIS413",
                        method: "post",
                        timeout: 600000,
                        data: {
                            action: "lab_report_query",
                            seltop: 1,
                            ...this.searchobj,
                            comblist: this.tempCombList,
                            daytype: this.daytype, //标本日期(1) 审核日期(2)报告日期(3)
                        },
                    })
                    .then((res) => {
                        var report_data = [];
                        if(this.exportsort) {
                            let sortarr = this.exportsort.split(" ");
                            if (sortarr[0] != "sampleno") {
                                if(sortarr[1] == "desc") report_data = res.RData.Data.sort((a, b) => b[sortarr[0]].localeCompare(a[sortarr[0]]));
                                else report_data = res.RData.Data.sort((a, b) => a[sortarr[0]].localeCompare(b[sortarr[0]]));
                            } 
                            else{
                                if(sortarr[1] == "desc") report_data = res.RData.Data.sort((a, b) => b[sortarr[0]] - a[sortarr[0]]);
                                else report_data = res.RData.Data.sort((a, b) => a[sortarr[0]] - b[sortarr[0]]);
                            }
                        }
                        else report_data = res.RData.Data;
                        this.report_Loading = false;
                        this.btnExportRpt(report_data);
                    })
                    .catch((e) => {
                        console.log("error", e);
                        this.report_Loading = false;
                    });
            } else this.btnExportRpt(this.$refs.reporttable.afterFullData);
        },
        rptitemChange(code, name) {
            this.searchobj.rpt_itemcode = code;
            this.rptitemname = name;
            this.getResultArea(1, code);
        },
        reportuserChange(code, name) {
            this.searchobj.report_user = code;
            this.reportusername = name;
        },
        reqdocChange(code, name) {
            this.searchobj.req_docno = code;
            this.reqdocname = name;
        },
        reportcommChange(code, name) {
            this.searchobj.report_comm = code;
            this.reportcommname = name;
        },
        hospChange(code, name) {
            this.searchobj.hospcode = code;
            this.hospname = name;
        },
        combChange(code, name) {
            this.searchobj.combno = code;
            this.combname = name;
        },
        btnExportRpt(report_date) {
            // let data = [];
            // data = this.getExportData();
            // let book = XLSX.utils.book_new();
            // let sheet = XLSX.utils.json_to_sheet(data, { skipHeader: true });
            // XLSX.utils.book_append_sheet(book, sheet);
            // let wbout = XLSX.write(book, {
            //     bookType: "xlsx",
            //     bookSST: false,
            //     type: "binary",
            // });
            // let blob = new Blob([this.toBuffer(wbout)], {
            //     type: "application/octet-stream",
            // });
            // // 保存导出
            // FileSaver.saveAs(blob, "LIS413 阳性表/传染病报表 .xlsx");
            var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
            let tableColumn = this.$refs.reporttable.getColumns();
            let exportColumn = [];
            if (rightlocalStorage && rightlocalStorage.length > 0) {
                rightlocalStorage.forEach((item) => {
                    exportColumn.push({
                        title: item.extitle ? item.extitle : item.title,
                        field: item.property,
                    });
                });
            } else {
                tableColumn.forEach((item) => {
                    exportColumn.push({ title: item.title, field: item.property });
                });
            }
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcel(report_date, exportColumn, "LIS413 阳性表/传染病报表 .xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let startdt = this.daytype == "1" ? this.searchobj.sample_startdt : (this.daytype == "2" ? this.searchobj.rechk_startdt : this.searchobj.report_startdt);
            let enddt = this.daytype == "1" ? this.searchobj.sample_enddt : (this.daytype == "2" ? this.searchobj.rechk_enddt : this.searchobj.report_enddt);
            let filtertxt = this.datename + ":" + XEUtils.toDateString(startdt, "yyyy-MM-dd") + "至" + XEUtils.toDateString(enddt, "yyyy-MM-dd") + "; ";
            if(this.searchobj.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) =>  ("," + this.searchobj.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.rpt_itemcode) filtertxt += "报告项目:" + this.rptitemname + "; ";
            if(this.searchobj.sampleno) filtertxt += "标本号:" + this.searchobj.sampleno + "; ";
            if(this.searchobj.report_user) filtertxt += "检验医生:" + this.reportusername + "; ";
            if(this.searchobj.req_docno) filtertxt += "送检医生:" + this.reqdocname + "; ";
            if(this.searchobj.result_min) filtertxt += "数值结果<" + this.searchobj.result_min + "; ";
            if(this.searchobj.result_max) filtertxt += "数值结果>" + this.searchobj.result_max + "; ";
            if(this.searchobj.specimen_code) filtertxt += "标本类型:" + this.getOptionName(this.specimenOption.filter((item) =>  ("," + this.searchobj.specimen_code + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.report_comm) filtertxt += "报告备注:" + this.reportcommname + "; ";
            if(this.searchobj.hospcode) filtertxt += "送检医院:" + this.hospname + "; ";
            if(this.searchobj.resultcomb) filtertxt += "多项目条件:" + this.getOptionName(this.resultcombOption.filter((item) =>  this.searchobj.resultcomb == item.data)) + "; ";
            if(this.searchobj.result_str) filtertxt += "文字结果" + (this.searchobj.result_mh == "1" ? "模糊查询" : "") + ":" + this.searchobj.result_str + "; ";
            if(this.searchobj.pat_diag) filtertxt += "临床诊断:" + this.searchobj.pat_diag + "; ";
            if(this.searchobj.pat_typecode) filtertxt += "病人类型:" + this.getOptionName(this.pattypeOption.filter((item) =>  ("," + this.searchobj.pat_typecode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.ischeck) filtertxt += "审核状态:" + (this.searchobj.ischeck=="0" ? "已审核" : this.searchobj.ischeck=="1" ? "未审核" : "全部") + "; ";
            if(this.searchobj.txtinfo1) filtertxt += "文字描述:" + this.searchobj.txtinfo1 + "; ";
            if(this.searchobj.lab_advice) filtertxt += "检验意见:" + this.searchobj.lab_advice + "; ";
            if(this.searchobj.combno) filtertxt += "病区组:" + this.combname + "; ";
            if(this.searchobj.req_deptno) filtertxt += "申请科室:" +  this.getOptionName(this.deptOption.filter((item) =>  ("," + this.searchobj.req_deptno + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.nameoutstr) filtertxt += "姓名剔除文字:" + this.searchobj.nameoutstr + "; ";
            if(this.searchobj.pat_no) filtertxt += "病历号:" + this.searchobj.pat_no + "; ";
            if(this.searchobj.agemin || this.searchobj.agemax) filtertxt += "年龄:" + this.searchobj.agemin + "至" + this.searchobj.agemax + "; ";
            if (this.searchobj.resultnumflag == "1") filtertxt += "原始数值; ";
            if (this.searchobj.nameflag == "1") filtertxt += "剔除无姓名; ";
            if (this.searchobj.barcodeflag == "1") filtertxt += "剔除无条码; ";
            if(this.searchobj.req_wardno) filtertxt += "所属病区:" +  this.getOptionName(this.wardOption.filter((item) =>  ("," + this.searchobj.req_wardno + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.pat_sex) filtertxt += "性别:" + (this.searchobj.pat_sex == "1" ? "男" : this.searchobj.pat_sex == "2" ? "女" : "全部") + "; ";
            if(this.searchobj.pat_idcardno) filtertxt += "身份证号:" + this.searchobj.pat_idcardno + "; ";
            if(this.txtpatid) filtertxt += "病人ID:" + this.txtpatid + "; ";
            if (this.searchobj.mixrpt) filtertxt += "混样报告:" + this.getMixRptName() + "; ";
            if (this.searchobj.upresult_flag == "1") filtertxt += "上次结果; ";
            if (this.searchobj.firstresult_flag == "1") filtertxt += "首次结果; ";
            if (this.searchobj.dblclickdel == "1") filtertxt += "双击明细剔除; ";
            return filtertxt;
        },
        getMixRptName() {
            let name = "";
            switch(this.searchobj.mixrpt) {
                case "1":
                    name = "混样主报告和非混样报告";
                    break;
                case "2":
                    name = "混样明细报告和非混样报告";
                    break;
                case "3":
                    name = "非混样报告";
                    break;
                case "4":
                    name = "混样报告";
                    break;
                case "5":
                    name = "仅混样主报告";
                    break;
                case "6":
                    name = "仅混样明细报告";
                    break;
                default:
                    name = "全部报告";
                    break;
            }
            return name;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("display")) {
                        optionname += item.display + ",";
                    } else {
                        optionname += item.label + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        //新增审核日期
        handleCommand(name) {
            this.datename = name;
            if (name == "标本日期") this.daytype = "1";
            else if (name == "审核日期") this.daytype = "2";
            else if (name == "报告日期") this.daytype = "3";
        },
        getExportData(type) {
            let datas = [];
            datas = this.$refs.reporttable.afterFullData;
            var allcolumns = this.$refs.reporttable.getColumns();
            var tableColumn = [];
            for (let i = 0; i < allcolumns.length; i++) {
                tableColumn.push({
                    field: allcolumns[i].property,
                    title: allcolumns[i].title,
                });
            }
            let columns = tableColumn.filter((item) => item.field);
            let headers = [columns.map((item) => item.title)];
            return headers.concat(
                datas.map((row) => {
                    return columns.map((column) => {
                        return row[column.field];
                    });
                })
            );
        },
        popMultipleChk_R(e, fieldname, option, title) {
            let temp = XEUtils.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.dialogMultipleVisible_R = true;
        },
        closedialog_R(value, name) {
            if (value != "close") {
                let row = this.$refs.nomatch_table.getCurrentRow();
                if (row) {
                    row.resistrules = value;
                }
            }
            this.dialogMultipleVisible_R = false;
        },
    },
};
</script>

<style scoped>
::v-deep el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
.middle-tab-bottom {
    position: absolute;
    top: 0px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.pagetop {
    left: 0;
    right: 0;
    height: 215px;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}
.pagebottom {
    position: absolute;
    width: 100%;
    left: 0;
    margin-top: 4px;
    height: 36px;
    bottom: 0px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
}
.middle-right {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 570px;
    right: 0px;
}

.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table tr td:nth-child(1) {
    width: 80px;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
.avatar {
    width: 178px;
    height: 178px;
    display: block;
}

.avatar-uploader-icon1 {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 50px;
    line-height: 50px;
    text-align: center;
}
.avatar1 {
    width: 178px;
    height: 50px;
    display: block;
}
.middle-tab-top {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 200px;
}
.middle-bottom {
    position: absolute;
    top: 37px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.middle-tab-bottom {
    position: absolute;
    top: 203px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.detail-operation {
    display: flex;
    padding: 0px 2px 0px 5px;
    margin: 5px 0;
}
.detail-right {
    right: 5px;
    position: relative;
    display: inline;
    align-items: center;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 0;
}
::v-deep .colrow {
    background-color: #c0ffc0;
}
::v-deep .el-textarea__inner {
    padding: 0px 5px;
}
</style>